<template>
	<view>
		<u-navbar title="計算管道" placeholder autoBack>
			<view class="flexright xiaohui" slot="right" @click="jumpurl('/pages/workbench/tianjiajsfs')">添加</view>
		</u-navbar>
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
			</view>
			<view class="mainpadding_top  ffffff radius" style="position: relative;" v-for="item in list.data"
				:key="item.id" @click="selectFormula(item)">
				<view class="fuwulable">{{item.code}}</view>
				<view class="pdl">
					<view class="titletext hei_text bold">{{item.name}}</view>
					<view class="margin_top xiaohui">
						公式：<text v-if="item.type!=2">（寬{{item.wei_a}}{{item.wei_b}}）{{item.wei_c}}</text>
						<text v-if="item.type!=1">（高{{item.hei_a}}{{item.hei_b}}）{{item.hei_c}}</text>
						{{item.numval}}
					</view>
					<view class="flexbetween xiaohui margin_top">
						<view v-if="item.type==0">類型：輸入寬高</view>
						<view v-if="item.type==1">類型：輸入寬</view>
						<view v-if="item.type==2">類型：輸入高</view>
						<view v-if="item.type==3">類型：寬高取最大</view>
						<view v-if="item.type==4">類型：寬高取最小</view>
						<view>小數：{{item.num}}</view>
						<view>單位：{{item.size}}</view>
					</view>
				</view>
				<view class="flexright margin_top">
					<view class="flexleft margin_right" @click.stop="jumpurl(`/pages/workbench/tianjiajsfs?id=${item.id}`)">
						<u-icon name="edit-pen" color="#999" size="16"></u-icon>
						<view class="xiaohei">編輯</view>
					</view>
					<view class="flexleft" @click.stop="remove(item.id)">
						<u-icon name="trash" color="#999" size="16"></u-icon>
						<view class="xiaohei">刪除</view>
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="show" showCancelButton confirmColor="#ffb800" @cancel="show=false" @confirm="confirm" confirmText="確認" cancelText="取消">
			<view class="slot-content color_ling text_weight text">
				您確定要刪除計算管道嗎？
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				shop_id: uni.getStorageSync("shop_id"),
				list: {
					data: []
				},
				id:"",//要刪除的及計算方式id
				selectType:0,
			}
		},
		onLoad(options) {
			if(options.selectType){
				this.selectType=options.selectType
			}
		},
		onShow() {
			this.getFormulaList()
		},
		methods: {
			async getFormulaList() {
				let _this = this
				let res = await this.http.request('/api/shop/listFor', 'POST', {
					shop_id: this.shop_id, //店鋪id
				})
				if (res.code == 1) {
					this.list.data = res.data
				} else if (res.code == 0) {
					// this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			remove(id) {
				this.id = id
				this.show = true
			},
			async confirm() {
				let _this = this
				let res = await this.http.request('/api/shop/Fordel', 'POST', {
					shop_id: this.shop_id, //店鋪id
					id:this.id
				})
				if (res.code == 1) {
					this.http.toast("刪除成功！")
					let index=this.list.data.findIndex(item=>{
						return this.id==item.id
					})
					this.list.data.splice(index,1)
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
				this.show=false
			},
			selectFormula(item){ //编辑商品選擇公式
				if(this.selectType==0){
					return false
				}
				uni.$emit("selectFormula",item)
				uni.navigateBack(1)
			}
		}
	}
</script>

<style>

</style>